package com.lee.taste.spider.sohu;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.lee.taste.spider.SpringUtils;
import com.lee.taste.spider.sohu.entity.Brand;
import com.lee.taste.spider.sohu.entity.Corporation;
import com.lee.taste.spider.sohu.entity.Model;
import com.lee.taste.spider.sohu.spider.BrandSpider;
import com.lee.taste.spider.sohu.spider.CorpSpider;
import com.lee.taste.spider.sohu.spider.ModelSpider;

public class SohuCar {

	private static final Logger logger = LoggerFactory.getLogger(SohuCar.class);

	public static void main(String[] args) throws Exception {
		ApplicationContext context = new ClassPathXmlApplicationContext("sohu.xml");
		SpringUtils.setContext(context);
		List<Brand> brands = BrandSpider.crawl("http://db.auto.sohu.com/cxdata/xml/basic/brandList.xml");
		for(Brand b : brands){
			BrandSpider.crawlSales("http://db.auto.sohu.com/cxdata/xml/sales/brand/brand"+b.getId()+"sales.xml" , b);
			List<Model> models = ModelSpider.crawl("http://db.auto.sohu.com/cxdata/xml/basic/brand"+b.getId()+"ModelListWithCorp.xml");
			for(Model m : models){
				ModelSpider.crawlSales("http://db.auto.sohu.com/cxdata/xml/sales/model/model"+m.getId()+"sales.xml");
			}
		}
		List<Corporation> corps =  CorpSpider.crawl("http://db.auto.sohu.com/cxdata/xml/basic/corpList.xml");
		CorpSpider.crawlSales("http://db.auto.sohu.com/cxdata/xml/sales/corp/corpCNSales.xml");
		for(Corporation corp : corps){
			CorpSpider.crawlSales("http://db.auto.sohu.com/cxdata/xml/sales/corp/corp"+corp.getId()+"Sales.xml");
		}
	}
}
